import binutils

class ALU(object):
    def __init__(self, bittedness = 8):
        self.b = bittedness

    def add(self, a, b):
        # string of binary reps
        repa = "{0:b}".format(a);
        repb = "{0:b}".format(b);

        print("a", repa)
        print("b", repb)

        # paddings
        pada = self.b - len(repa)
        padb = self.b - len(repb)

        # padding temp variables
        pa = pada
        pb = padb

        print(pada, padb)

        result, carryout = 0, 0

        i = 0
        while (i is not self.b):
            # number dissection for digits!

            # digit is 0 if number is still padded
            da = 0
            db = 0
            # if padding is still necessary
            if (pa is not 0):
                pa -= 1
            else:
                da = int(repa[i - pada])
            if (pb is not 0):
                pb -= 1
            else:
                db = int(repb[i - padb])

            # actual digit logic, addition!
            #print(da)
            #print(db)
            result, carryout = binutils.add(da, db, carryout)
            print(result, carryout)

            # increment loop var
            i += 1;
